package com.zyf.chapter02.structure.bridge;

import com.zyf.chapter01.principle.SOLID.OCP.NotificationEmergencyLevel;
import com.zyf.chapter01.principle.SOLID.OCP.handler.ErrorAlertHandler;

import java.util.List;

/**
 * 发送告警信息
 * 错误处理类请参照 {@link ErrorAlertHandler}
 * @author yifeng
 * @see ErrorAlertHandler
 */
public class OldNotification {
    private List<String> emailAddresses;
    private List<String> telephones;
    private List<String> wechatIds;

    public OldNotification() {
    }

    public void setEmailAddresses(List<String> emailAddresses) {
        this.emailAddresses = emailAddresses;
    }

    public void setTelephones(List<String> telephones) {
        this.telephones = telephones;
    }

    public void setWechatIds(List<String> wechatIds) {
        this.wechatIds = wechatIds;
    }

    /**
     * <p>
     * 问题在于，存在太多 if-else 分值逻辑，且 if-else 中代码逻辑都比较复杂，发送通知的所有逻辑都扎堆
     * 在 Notification 类中。
     * @param level 通知等级
     * @param message 通知信息
     */
    public void notify(NotificationEmergencyLevel level, String message) {
        if (level.equals(NotificationEmergencyLevel.SEVERE)) {
            // ... 自动语音电话
        } else if (level.equals(NotificationEmergencyLevel.URGENCY)) {
            // 发微信
        } else if (level.equals(NotificationEmergencyLevel.NORMAL)) {
            // 发邮件
        } else if (level.equals(NotificationEmergencyLevel.TRIVIAL)) {
            // 发邮件
        }
    }
}
